package com.cn.xiongmeng.czlxz.ui;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;

import com.cn.xiongmeng.czlxz.R;

public class LoadingFragment extends Fragment {
    private static final String TAG = "LoadingFragment";
    private ImageView loadingImage;

    public LoadingFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View rootView = inflater.inflate(R.layout.fragment_loading, container, false);

        loadingImage = rootView.findViewById(R.id.loading_image);

        rootView.post(new Runnable() {
            @Override
            public void run() {
                // 在这里更新UI
                // loadingImage.setVisibility(ImageView.VISIBLE);
                startRotationAnimation(); // 开始旋转动画
            }
        });

        return rootView;
    }
    @Override
    public void onPause() {
        super.onPause();

        Log.d(TAG, "onPause");
    }

    @Override
    public void onStop() {
        super.onStop();

        Log.d(TAG, "onStop");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

        Log.d(TAG, "onDestroy");
    }

    private void startRotationAnimation() {
        RotateAnimation rotateAnimation = new RotateAnimation(0f, 360f,
                RotateAnimation.RELATIVE_TO_SELF, 0.5f,
                RotateAnimation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setDuration(1000); // 设置旋转周期
        rotateAnimation.setRepeatCount(RotateAnimation.INFINITE); // 无限旋转

        // 启动旋转动画
        loadingImage.startAnimation(rotateAnimation);
    }
}